﻿#include "Render.h"

#include "Camera.h"
#include "Mesh.h"
#include "Scence.h"
#include "Scence/RTTScence.h"
#include "Scence/ShadowScence.h"

void FRender::Draw(float DateTime)
{
	Scene->Draw(DateTime);
}


void FRender::BeginDraw()
{
	glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
}

void FRender::EndDraw()
{
	glfwSwapBuffers(Window);
	glfwPollEvents();
}


void FRender::Init(GLFWwindow* InWindow)
{
	Window = InWindow;

	Scene = std::make_shared<FShadowScence>();
	//Scene = std::make_shared<FRTTScene>();
	//Scene = std::make_shared<FInstanceScence>();
	//Scene = std::make_shared<FCubMapScene>();
	//Scene = std::make_shared<FAdvanceScene>();
	//Scene = std::make_shared<FModelTestScene>();

	Scene->Init(this);
}

void FRender::Destory()
{
	Scene->Destory();
	Scene = nullptr;
}

std::shared_ptr<FCamera> FRender::GetCamera() const
{
	return Scene->GetCamera();
}

void FRender::OnFramebufferSizeChange(const int32_t InWidth, const int32_t InHeight)
{
	Width = InWidth;
	Height = InHeight;

	glViewport(0, 0, Width, Height);

	Aspect = static_cast<float>(Width) / static_cast<float>(Height);
}
